<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item :label="this.timeTitle" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="time">
                <j-date :placeholder="this.timeTitle" v-model="model.time" :show-time="true"
                        date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>

  </j-modal>
</template>

<script>
import {httpAction} from "@api/manage";

export default {
  name: "editStartWork",
  data() {
    return {
      model: {},
      startStatus: "",
      timeTitle: '',
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      confirmLoading: false,
      validatorRules: {
        time: [{ required: true, message: '时间不能为空' }],
      },
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      url: {
        edit: "/ghCustomerProgress/edit",
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  methods: {
    editStartWork(startStatus, timeTitle, record) {
      this.startStatus = startStatus;
      this.timeTitle = timeTitle;
      this.model = record;
    },
    add () {
      this.visible=true
      this.$nextTick(()=>{
        this.$refs.realForm.add();
      })
    },
    edit (record) {
      this.visible=true
      this.$nextTick(()=>{
        this.$refs.realForm.edit(record);
      })
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = 'post';
          httpurl += this.url.edit;

          method = 'post';
          if(this.startStatus === 1) {
            this.model.startStatus = 3;
            this.model.startWorkTime = this.model.time;
          } else {
            this.model.startStatus = 6;
            this.model.endWorkTime = this.model.time;
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.model = {};
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            this.visible = false;
          })
        }
      })
    },
    submitCallback(){
      this.$emit('ok');
      this.visible = false;
    },
    handleCancel () {
      this.close()
    }
  }
}
</script>

<style scoped>

</style>